<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class CouponShopIncome extends Model
{
    protected $dateFormat = 'U';
    //
    protected $table = "lexiang_coupon_shopincome";

    public function add($data)
    {
    	$this->coupon_shop_id = $data['shop_id'];
    	$this->coupon_item_id = $data['coupon_id'];
    	$this->money = $data['money'];

    	$res = CouponShop::find($this->coupon_shop_id);

    	$res->amount = $res->amount+$data['money'];

    	if(!$res->save()){
    		return [
    			'success'=>false,
    			'code'=>'004',
    			'message'=>'金额纪录失败，请稍后再试！'
    		];
    	}

    	if($this->save()){
    		return ['success'=>true,'code'=>'000','message'=>'记录成功','amount'=>$res->amount];
    	}else{
    		return ['success'=>false,'code'=>'006','message'=>'记录出错，请稍后再试！'];
    	}
    }
}
